package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    void insert(Orders order);

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);

    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select *from orders  where id=#{id}")
    Orders getById(Long id);

    @Select("select  count(*)  from orders where status=#{status}")
    Integer countStatus(Integer toBeConfirmed);

    @Select("select *from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(@Param("status") Integer status, @Param("orderTime") LocalDateTime orderTime);


    Double sumByMap(Map map);

    @Select("select count(id) from user where create_time< #{beginTime} and create_time>#{endTime}")
    Integer getNewUserCount(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select count(id) from user where  create_time>#{endTime}")
    Integer getTotalUserCount(LocalDateTime endTime);

    Integer getOrderCount(LocalDateTime begin, LocalDateTime end, Object status);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);


    Integer countByMap(Map map);
}
